package com.example.rocketspringbootsuper.consumer;

import com.example.rocketspringbootsuper.bean.MessageEvent;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName ConsumerService
 * @Author swj
 * @Date 2020/9/28 17:11
 */
@Component
public class ConsumerService {
    @EventListener(condition = "#event.msgs[0].topic == 'user-topic' && #event.msgs[0].tags=='white'")
    public void rocketmqMsgListener(MessageEvent event){
        try{
            List<MessageExt> msgs = event.getMsgs();
            for (MessageExt msg : msgs) {
                System.out.println("消费消息"+new String(msg.getBody()));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
